import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'
import test from '@/components/test'
import new_test from '@/components/new_test'
import register from '@/components/register'
import login from '@/components/login'
import wb_login from '@/components/wb_login'
import myprofile from '@/components/myprofile'
import editcategory from '@/components/editcategory'
import updatecate from '@/components/updatecate'
import addgoods from '@/components/addgoods'



Vue.use(Router)

var routes = [

        //拦截器的使用
        {
          path:'/myprofile',
          name:'myprofile',
          component:myprofile,
          beforeEnter: (to,from,next) => {
           
            //判断是否登录
            if(localStorage.getItem('username')){

              console.log('已登陆');
              next();

            }else{

              console.log('未登录');
              next('/login')

            }
          }

        },
      
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/cart',
          name:'cart',
          component:cart
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/detail',
          name:'detail',
          component:detail
        },
        {
          path:'/mytest',
          name:'mytest',
          component:mytest
        },
        {
          path:'/test',
          name:'test',
          component:test
        },
        {
          path:'/new_test',
          name:'new_test',
          component:new_test
        },
        {
          path:'/register',
          name:'register',
          component:register
        },
        {
          path:'/login',
          name:'login',
          component:login
        },
        {
          path:'/wb_login',
          name:'wb_login',
          component:wb_login
        },
        {
          path:'/myprofile',
          name:'myprofile',
          component:myprofile
        },
        {
          path:'/editcategory',
          name:'editcategory',
          component:editcategory
        },
        {
          path:'/updatecate',
          name:'updatecate',
          component:updatecate
        },
        {
          path:'/addgoods',
          name:'addgoods',
          component:addgoods
        },
        
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
